from appium import webdriver
from appium.webdriver.common.appiumby import By
from time import sleep

desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '7'
desired_caps['deviceName'] = '127.0.0.1:62001'
desired_caps['app'] = r'E:\test\apk\zuoyebang.apk'
desired_caps['appPackage'] = r'com.baidu.homework'
desired_caps['appActivity'] = r'com.baidu.homework.activity.init.InitActivity'
desired_caps['noReset'] = False
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
driver.implicitly_wait(10)
sleep(3)
# 点击同意
try:
    ele = driver.find_element(By.ID, 'com.baidu.homework:id/iknow_alert_dialog_button2')
except Exception as e:
    print('no agree')
else:
    ele.click()

    # 点击 同意
try:
    ele = driver.find_element(By.ID, 'com.tal.kaoyan:id/tv_skip')
except Exception as e:
    print('no agree')
else:
    ele.click()
# 获取 电话 允许
try:
    ele = driver.find_element(By.ID,'com.android.packageinstaller:id/permission_allow_button')
except Exception as e:
    print('no obtain')
else:
    ele.click()
# 照片确定 允许
try:
    ele = driver.find_element(By.ID,'com.android.packageinstaller:id/permission_allow_button')
except Exception as e:
    print('no determine')
else:
    ele.click()
# 密码点击 允许
try:
    ele = driver.find_element(By.CLASS_NAME,'android.widget.LinearLayout')
except Exception as e:
    print('no click')
else:
    ele.click()
